<template>
    <view class="back" :style="{ top: statusBarHeight }" @click="BackPage()">
        <!-- <view :style="{ height: statusBarHeight }" class="status-bar"></view> -->

        <!-- <uni-nav-bar left-icon="back" :statusBar="true" :fixed="true" left-text="返回" backgroundColor="transparent"></uni-nav-bar> -->

        <view v-if="home_mode === 'arrow'">
            <!-- 箭头黑色 -->
            <image class="image" v-if="color === 'black'"
                src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-0b7370d2-b47f-4848-bcdd-1273a6a32057/2846696c-3e43-4b04-a6ea-1ff5bd86724c.png">
            </image>
            <image class="image" v-else
                src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-0b7370d2-b47f-4848-bcdd-1273a6a32057/4ba2e0b5-fbda-4cee-bdc5-523258386ccd.png">
            </image>
        </view>
        <view v-else-if="home_mode === 'home'">
            <!-- 房子黑色 -->
            <image class="image" v-if="color === 'black'"
                src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-0b7370d2-b47f-4848-bcdd-1273a6a32057/cc14e3eb-9565-46f9-bbf2-89769c96f91d.png">
            </image>
            <image class="image" v-else
                src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-0b7370d2-b47f-4848-bcdd-1273a6a32057/79c95be2-b862-4803-a75d-9a3fae7bdf16.png">
            </image>
        </view>

    </view>
</template>

<script>
    export default {
        name: "d-back",
        data() {
            return {
                // 是不是从首页进来的
                home_mode: "arrow",
                // 系统高度
                statusBarHeight: 20
            };
        },
        props: {
            "color": {
                default: "white"
            },
        },
        created() {
            // 获取状态栏高度
            console.log("uni.getSystemInfoSync()")
            console.log(uni.getSystemInfoSync())
            // 加的这10，是为了对齐右侧关闭按钮
            this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 10 + 'px'

            console.log("getCurrentPages()")
            // 如果 getCurrentPages() 的数组长度大于1，就说明是从首页进来的，如果不是，就说明是直接进入的这个内页
            console.log(getCurrentPages())
            if (getCurrentPages().length > 1) {
                this.home_mode = "arrow"
            } else {
                this.home_mode = "home"
            }
        },
        methods: {
            BackPage() {
                console.log('BackPage');
                console.log(getCurrentPages())
                if (getCurrentPages().length > 1) {
                    uni.navigateBack({
                        delta: 1
                    });
                } else {
                    uni.reLaunch({
                        url: '/pages/index/index'
                    })
                }
            },
            BackHome() {
                // if (getCurrentPages().length > 1) {
                // 	uni.navigateBack({
                // 		delta: getCurrentPages().length
                // 	})
                // } else {
                uni.reLaunch({
                    url: '/pages/index/index'
                })
                // }
            }
        }
    }
</script>

<style lang="scss" scoped>
    .back {
        position: fixed;
        left: 30rpx;
        z-index: 100;
        width: 200rpx;
        height: 100rpx;
    }

    .image {
        width: 60rpx;
        height: 60rpx;
        display: block;
    }

    // .image{
    //     width: 90rpx;
    //     height: 60rpx;
    //     display: block;
    //     padding: 10rpx 25rpx;
    //     box-sizing: border-box;
    //     border-radius: 50rpx;
    //     &.white {
    //         background-color: rgba(255, 255, 255, 0.6);
    //         border: 2rpx solid rgba(0, 0, 0, 0.1);
    //     }

    //     &.black {
    //         background-color: rgba(0, 0, 0, 0.15);
    //         border: 2rpx solid rgba(255, 255, 255, 0.25);
    //     }
    // }
</style>
